/*
** my_list.c for  in /home/georgi_v/rendu/PSU_2013_my_printf/libs
** 
** Made by georgi_v
** Login   <georgi_v@epitech.net>
** 
** Started on  Sat Nov 16 20:21:26 2013 georgi_v
** Last update Fri Dec  6 19:53:13 2013 georgi_v
*/

#include "my.h"

int	add_elem_front(t_list **list, data_t *data)
{
  t_list	*elem;

  if ((elem = malloc(sizeof(*elem))) == NULL)
    return (1);
  elem->data = data;
  elem->next = *list;
  *list = elem;
  return (0);
}

int	add_elem_end(t_list **list, data_t *data)
{
  t_list	*current;
  t_list	*elem;

  current = *list;
  if ((elem = malloc(sizeof(*elem))) == NULL)
    return (1);
  elem->data = data;
  elem->next = NULL;
  if (current == NULL)
    {
      *list = elem;
      return (0);
    }
  else
    {
      while (current->next != NULL)
	current = current->next;
      current->next = elem;
      return (0);
    }
}

int	get_list_size(t_list *list)
{
  int	cnt;

  cnt = 0;
  while (list != NULL)
    {
      cnt++;
      list = list->next;
    }
  return (cnt);
}

data_t	*get_node_by_char(t_list *list, char c)
{
  while (list != NULL)
    {
      if (list->data->fstr == c)
	return (list->data);
      list = list->next;
    }
  return (NULL);
}
